program constraint_maxmin;

class Test;
    rand bit [7:0] a; // 0 <= a <= 255
    rand bit [6:0] b; // 0 <= b <= 127

    constraint c_range {
        // 使用$指定最大值和最小值
        a inside {[$:4], [20:$]}; // 0 <= a <= 4 or 20 <= a <= 255
        b inside {[$:4], [20:$]}; // 0 <= b <= 4 or 20 <= b <= 127
    }
endclass

initial begin
    Test t = new();
    for (int i = 0; i < 10; i++) begin
        if (t.randomize()) begin
            $display("a=%0d, b=%0d", t.a, t.b);
        end else begin
            $display("randomize failed");
        end
    end
    $display("End of test");
end

endprogram
